import { http } from "@/utils/http";

// 报事报修查询参数
export interface RepairReportQueryDto {
  page?: number;
  limit?: number;
  contactPhone?: string;
  cellId?: number;
  keyword?: string;
}

// 报事报修基础数据
export interface RepairReportBase {
  id?: number;
  cellId: number;
  roomNumber: string;
  source: string;
  contactPerson: string;
  contactPhone: string;
  status: string;
  importance: string;
  acceptTime: string;
  requiredCompleteTime: string;
  details: string;
  appointmentTime: string;
  type: string;
  handler: string;
}

// 报事报修实体类
export interface RepairReport extends RepairReportBase {
  tenantId?: number;
  cellName?: string;
  createTime?: string;
  updateTime?: string;
  isDeleted?: boolean;
}

// 报事报修列表展示对象
export interface RepairReportListVo extends RepairReportBase {
  cellName: string;
}

// 报事报修更新DTO
export type UpdateRepairReportDto = RepairReportBase;

// 报事报修状态更新DTO
export interface UpdateRepairReportStatusDto {
  id: number;
  status: string;
}

// 通用响应类型
export interface ApiResult<T = any> {
  code: number;
  data: T;
  message: string;
}

// 分页响应类型
export interface PageResult<T = any> {
  records?: T[];
  list?: T[];
  total: number;
}

// 查询报事报修列表
export const getRepairReportList = (
  data: RepairReportQueryDto
): Promise<ApiResult<PageResult<RepairReportListVo>>> => {
  return http.request<ApiResult<PageResult<RepairReportListVo>>>(
    "post",
    "/repairReport/list",
    { data }
  );
};

// 根据ID查询报事报修详情
export const getRepairReportById = (
  id: number
): Promise<ApiResult<RepairReport>> => {
  return http.request<ApiResult<RepairReport>>(
    "get",
    `/repairReport/find?id=${id}`
  );
};

// 查询所有报事报修信息
export const getAllRepairReports = (): Promise<ApiResult<RepairReport[]>> => {
  return http.request<ApiResult<RepairReport[]>>(
    "get",
    "/repairReport/findAll"
  );
};

// 添加报事报修信息
export const addRepairReport = (
  data: UpdateRepairReportDto
): Promise<ApiResult<boolean>> => {
  return http.request<ApiResult<boolean>>("post", "/repairReport/add", {
    data
  });
};

// 修改报事报修信息
export const updateRepairReport = (
  data: UpdateRepairReportDto
): Promise<ApiResult<boolean>> => {
  return http.request<ApiResult<boolean>>("post", "/repairReport/update", {
    data
  });
};

// 修改报事报修状态
export const updateRepairReportStatus = (
  data: UpdateRepairReportStatusDto
): Promise<ApiResult<boolean>> => {
  return http.request<ApiResult<boolean>>(
    "post",
    "/repairReport/updateStatus",
    { data }
  );
};

// 删除报事报修信息
export const deleteRepairReport = (id: number): Promise<ApiResult<boolean>> => {
  return http.request<ApiResult<boolean>>(
    "get",
    `/repairReport/delete?id=${id}`
  );
};

// 批量删除报事报修信息
export const deleteRepairReportsBatch = (data: {
  ids: number[];
}): Promise<ApiResult<boolean>> => {
  return http.request<ApiResult<boolean>>("post", "/repairReport/deleteBatch", {
    data
  });
};
